<?php
use     
        Doctrine\Common\ClassLoader,
	Doctrine\ORM\Tools\Setup,
	Doctrine\ORM\EntityManager;

class CrudusuariosistemaController extends Zend_Controller_Action
{
    //--------------------------------------------------------------------------
    public function init()
    {   /* Initialize action controller here */
        $registry = Zend_Registry::getInstance();
        $this->_em = $registry->entitymanager;
    }
    //--------------------------------------------------------------------------
    public function indexAction()
    {
        // action body
    }
    //--------------------------------------------------------------------------
    public function listarAction()
    {   
        /*$usuarios = $this->_em 
            ->createQuery('select u from Default_Model_Usuarios_Usuariosistema u')
            ->getResult(); */
        $usuarios = $this->_em->getRepository('Default_Model_Usuarios_Usuariosistema')->todos();
        
	$this->view->usuarios = $usuarios;
    }
    //--------------------------------------------------------------------------
    public function crearAction()
    {
	$request = $this->getRequest();
        $form    = new Application_Form_Usuariosistema();

	if ($this->getRequest()->isPost()) {
            if ($form->isValid($request->getPost())) {
		$registro = $form->getValues();
                $this->persistirDatos($registro);
                return $this->_helper->redirector('listar');
            }
        }
 	$this->view->form = $form;
    }
    //--------------------------------------------------------------------------
    private function persistirDatos($registro)
    {	$testEntity = new Default_Model_Usuarios_Usuariosistema;
        $testEntity->setNombre($registro['unnombre']);
        $testEntity->setClave(sha1($registro['unaclave']));
        $this->_em->persist($testEntity);
        $this->_em->flush();
    }
    //--------------------------------------------------------------------------


}





